package com.yoso.springcloud.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yoso.springcloud.service.PaymentService;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Date: 2021/10/14 15:14
 */
@Service
public class PaymentServiceImpl implements PaymentService {
    @Override
    public String paymentInfo_OK(Integer id) {
        return "线程:" + Thread.currentThread().getName() + "\t"+"paymentInfo_OK,id:" + id;
    }

/*    @HystrixCommand(fallbackMethod = "payment_TimeoutHandler",commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "4000")})//4秒钟以内是正常的业务逻辑*/
    @Override
    public String payment_Timeout(Integer id) {
        int timeNumber = 7000;
        try {
            Thread.sleep(timeNumber);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程" + Thread.currentThread().getName() + "\t"+"paymentInfo_TimeOut,id:" + id + "\t" + "耗时：" + timeNumber + "ms";
    }

    public String payment_TimeoutHandler(Integer id){
        return "线程：" + Thread.currentThread().getName() + "payment_TimeoutHandler,系统繁忙，请稍后再试\t0(ππ)0";
    }
}
